<template>
  <a-drawer
    width="55%"
    :title="formTitle"
    :label-col="4"
    :wrapper-col="14"
    :visible="open"
    :body-style="{ height: 'calc(100vh - 100px)', overflow: 'auto' }"
    @close="cancel"
  >
    <div>
      <a-card :bordered="false" class="table-card">
        <!-- 增加 -->
        <biz-month-model-detials-add-form
          v-if="showAddModal"
          ref="bizMonthModelDetialsAddForm"
          @ok="getList"
          @close="showAddModal = false"
        />
        <!-- 编辑 -->
        <biz-month-model-detials-edit-form
          v-if="showEditModal"
          ref="bizMonthModelDetialsEditForm"
          @ok="getList"
          @close="showEditModal = false"
        />
        <advance-table
          title="月报模版配置详情"
          :pagination="{
            current: queryParam.pageNum,
            pageSize: queryParam.pageSize,
            total: total,
            showSizeChanger: true,
            showLessItems: true,
            showQuickJumper: true,
            showTotal: (total, range) =>
              `第 ${range[0]}-${range[1]} 条，总计 ${total} 条`,
            onChange: changeSize,
            onShowSizeChange: onShowSizeChange,
          }"
          tableKey="base-bizMonthModelDetials-index-table"
          rowKey="id"
          size="middle"
          @refresh="getList"
          :columns="columns"
          :data-source="bizMonthModelDetialsList"
          :loading="loading"
          :format-conditions="true"
        >
          <div class="table-operations" slot="button">
            <a-button
              type="primary"
              @click="handleAdd"
              v-hasPermi="['biz:bizMonthModelDetials:add']"
            >
              <a-icon type="plus" />新增
            </a-button>
          </div>

          <span slot="operation" slot-scope="{ text, record }">
            <a
              @click="handleUpdate(record)"
              v-hasPermi="['biz:bizMonthModelDetials:edit']"
            >
              修改
            </a>
            <a-divider
              type="vertical"
              v-hasPermi="['biz:bizMonthModelDetials:remove']"
            />
            <a
              @click="handleDelete(record)"
              v-hasPermi="['biz:bizMonthModelDetials:remove']"
            >
              删除
            </a>
          </span>
          <span slot="rowindex" slot-scope="{ index }">
            {{ index + 1 }}
          </span>
        </advance-table>
      </a-card>
    </div>
  </a-drawer>
</template>
<script>
import {
  listBizMonthModelDetials,
  delBizMonthModelDetials,
  exportBizMonthModelDetials,
} from "@/api/biz/bizMonthModelDetials";
import AdvanceTable from "@/components/pt/table/AdvanceTable";
import BizMonthModelDetialsAddForm from "@/views/biz/monthmodeldetials/modules/BizMonthModelDetialsAddForm";
import BizMonthModelDetialsEditForm from "@/views/biz/monthmodeldetials/modules/BizMonthModelDetialsEditForm";
export default {
  name: "BizMonthModelDetials",
  components: {
    AdvanceTable,
    BizMonthModelDetialsAddForm,
    BizMonthModelDetialsEditForm,
  },
  data() {
    return {
      open: false,
      spinning: false,
      delayTime: 100,
      id: undefined,
      formTitle: "添加月报模版配置详情",
      // 表单参数
      form: {},
      rules: {},
      showAddModal: false,
      showEditModal: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 选中的主键集合
      selectedRowKeys: [],
      // 选中的数据集合
      selectedRows: [],
      // 高级搜索 展开/关闭
      advanced: false,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // label的百分比
      labelCol: { span: 6 },
      // 内容区域的百分比
      wrapperCol: { span: 18 },
      // 月报模版配置详情表格数据
      bizMonthModelDetialsList: [],
      // 查询参数
      queryParam: {
        pageNum: 1,
        pageSize: 10,
        userId: undefined,

        deptId: undefined,

        userName: undefined,

        deptName: undefined,

        companyId: undefined,

        leimu: undefined,

        projects: undefined,

        sort: undefined,

        status: undefined,

        remark: undefined,
      },
      columns: [
        {
          title: "序号",
          dataIndex: "rowindex",
          ellipsis: true,
          align: "center",
          width: "5%",
          scopedSlots: { customRender: "rowindex" },
        },

        {
          title: "检查类目",
          dataIndex: "leimu",
          ellipsis: true,
          align: "left",
          width: "15%",
        },
        {
          title: "检查项目",
          dataIndex: "projects",
          ellipsis: true,
          align: "left",
          width: "30%",
        },
        {
          title: "备注",
          dataIndex: "remark",
          ellipsis: true,
          align: "left",
          width: "30%",
        },

        {
          title: "操作",
          dataIndex: "operation",
          align: "center",
          width: "10%",
          scopedSlots: { customRender: "operation" },
        },
      ],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    onClose() {
      this.open = false;

      this.$emit("close");
    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.$emit("close");
    },
    handlePeiUpdate(row) {
      this.open = true;
      this.spinning = !this.spinning;
      const monthModelId = row.id;
      this.form.monthModelId = monthModelId;
      this.queryParam.monthModelId = monthModelId;
      this.getList().then((response) => {
        this.formTitle = "月报模版配置详情";
        this.spinning = !this.spinning;
      });
    },
    /** 查询月报模版配置详情列表 */
    getList() {
      this.loading = true;
      listBizMonthModelDetials(this.queryParam).then((response) => {
        this.bizMonthModelDetialsList = response.data.list;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParam.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParam = {
        pageNum: 1,
        pageSize: 10,
        userId: undefined,

        deptId: undefined,

        userName: undefined,

        deptName: undefined,

        companyId: undefined,

        leimu: undefined,

        projects: undefined,

        sort: undefined,

        status: undefined,

        remark: undefined,
      };
      this.handleQuery();
    },
    /** 翻页操作 */
    onShowSizeChange(current, pageSize) {
      this.queryParam.pageSize = pageSize;
      this.getList();
    },
    /** 翻页操作 */
    onSizeChange(current, size) {
      this.queryParam.pageNum = 1;
      this.queryParam.pageSize = size;
      this.getList();
    },
    /** 翻页操作 */
    changeSize(current, pageSize) {
      this.queryParam.pageNum = current;
      this.queryParam.pageSize = pageSize;
      this.getList();
    },
    /** 翻页操作 */
    onSelectChange(selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys;
      this.selectedRows = selectedRows;
      this.ids = this.selectedRows.map((item) => item.id);
      this.single = selectedRowKeys.length !== 1;
      this.multiple = !selectedRowKeys.length;
    },
    /** 查询折叠和展开操作 */
    toggleAdvanced() {
      this.advanced = !this.advanced;
    },
    handleAdd() {
      this.showAddModal = true;
      this.$nextTick(() =>
        this.$refs.bizMonthModelDetialsAddForm.handleAdd(this.form.monthModelId)
      );
    },
    handleUpdate(record, ids) {
      this.showEditModal = true;
      this.$nextTick(() =>
        this.$refs.bizMonthModelDetialsEditForm.handleUpdate(record, ids)
      );
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      var that = this;
      const bizMonthModelDetialsIds = row.id || this.ids;
      this.$confirm({
        title: "确认删除所选中数据?",
        onOk() {
          return delBizMonthModelDetials(bizMonthModelDetialsIds).then(() => {
            that.onSelectChange([], []);
            that.getList();
            that.$message.success("删除成功", 3);
          });
        },
        onCancel() {},
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      var that = this;
      this.$confirm({
        title: "是否确认导出?",
        content: "此操作将导出当前条件下所有数据而非选中数据",
        onOk() {
          return exportBizMonthModelDetials(that.queryParam).then(
            (response) => {
              that.download(response.msg);
              that.$message.success("导出成功", 3);
            }
          );
        },
        onCancel() {},
      });
    },
  },
};
</script>
